#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
#  File-Name:   baergDuellLowe_2025_replicationFile   		       		
#  Started:     25/01/31                 			
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
pkgs <- c('ggplot2','dplyr','conflicted','stringr','estimatr','grid',
          'gridExtra','broom','rsample','purrr','texreg','margins',
          'Hmisc','sandwich','magrittr','readr','summarytools',
          'tidyr','htestClust','xtable')
# Comment in below if packages need to be installed
# for (pkg in pkgs) install.packages(pkg, character.only = TRUE)
for (pkg in pkgs) library(pkg, character.only = TRUE)
conflict_prefer("filter", "dplyr")
conflict_prefer("select", "dplyr")

#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
# Load data
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
panelData <- read_csv('panelData.csv')
inflationData <- read_csv('inflationData.csv')

#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
# Descriptive stats and figures ----
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
# Number of subjects by wave ----
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
panelData %>%
  group_by(wave) %>%
  summarise(n=n()) 

panelData %>% 
  filter(nWaveExperiment==3) %>%
  group_by(wave) %>%
  summarise(n=n()) 

#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
# 3 Research design ----
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
# 3.6 Inflation in Germany ----
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
# Figure 1: ----
# Prior and posterior expectation inflation in our sample (mean and full 
# distribution) and real inflation in Germany and the Eurozone. The gray 
# horizontal line indicates the ECB's 2% target.
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
d1 <- inflationData %>%
  filter(
    GEO=="Euro area (EA11-2000, EA12-2006, EA13-2007, EA15-2008, EA16-2010, EA17-2013, EA18-2014, EA19)"|
    GEO=="Germany (until 1990 former territory of the FRG)") %>%
  mutate(ctry=ifelse(GEO=="Euro area (EA11-2000, EA12-2006, EA13-2007, EA15-2008, EA16-2010, EA17-2013, EA18-2014, EA19)",
    "Eurozone","Germany")) %>%
  select(TIME,ctry,Value) 

prior <- panelData %>% 
  lm_robust(prior~as.factor(wave)-1,data=.,clusters=id_g) %>% tidy() %>%
  mutate(wave=as.numeric(str_sub(term,-2,-1)),
    month=ifelse(wave==23,5,11),
    year=ifelse(wave==14,2014,2016),
    est_prior=estimate,
    lb_prior=conf.low,
    ub_prior=conf.high,
    lb2_prior=est_prior-1.6*std.error,
    ub2_prior=est_prior+1.6*std.error) %>%
  filter(wave==14) %>%
  select(month,year,est_prior,lb_prior,ub_prior,lb2_prior,ub2_prior)

posterior <- 
  panelData %>% filter(wave==14|wave==20|wave==23) %>% 
  lm_robust(posterior~as.factor(wave)-1,data=.,clusters=id_g) %>% tidy() %>%
  mutate(wave=as.numeric(str_sub(term,-2,-1)),
    month=ifelse(wave==23,5,11),
    year=ifelse(wave==14,2014,ifelse(wave==20,2015,2016)),
    est_posterior=estimate,
    lb_posterior=conf.low,
    ub_posterior=conf.high,
    lb2_posterior=est_posterior-1.6*std.error,
    ub2_posterior=est_posterior+1.6*std.error) %>%
  select(month,year,est_posterior,lb_posterior,ub_posterior,lb2_posterior,
    ub2_posterior)

d2 <- 
  panelData %>% 
  filter(wave==14|wave==20|wave==23) %>% 
  mutate(
    month=ifelse(wave==23,5,11),
    year=ifelse(wave==14,2014,ifelse(wave==20,2015,2016)),
    prior=ifelse(wave==14,prior,NA)) %>%
  select(month,year,prior,posterior)

d3 <- d1 %>%
  mutate(
    year=as.numeric(substr(TIME,1,4)),
    month=as.numeric(substr(TIME,6,8))) %>%
  filter(year==2014|year==2015|(year<=2016&month<=9)) %>%
  group_by(ctry) %>%
  mutate(index = order(year,month)) %>%
  pivot_wider(id_cols=c(year,month,index),names_from=ctry,values_from=Value) %>%
  full_join(d2) %>%
  left_join(posterior %>% left_join(prior)) %>%
  pivot_longer(cols=Eurozone:Germany,names_to='ctry')

pdf("figure1.pdf",height=4,width=8.5)
d3 %>% 
  ggplot() +
  geom_line(aes(y=value,x=index,group=ctry,linetype=ctry)) +
  scale_x_continuous(
    breaks=seq(1,33,2),
    labels=c(
      "2014.01","2014.03","2014.05","2014.07","2014.09","2014.11","2015.01","2015.03","2015.05","2015.06",
      "2015.09","2015.11","2016.01","2016.03","2016.05","2016.07","2016.09")) +
  labs(x="", y="Inflation") +
  geom_hline(aes(yintercept=0), colour="gray") +
  geom_hline(aes(yintercept=2), colour="gray", size=1) +
  geom_vline(aes(xintercept=11), colour="gray") +
  geom_vline(aes(xintercept=23), colour="gray") +
  geom_vline(aes(xintercept=29), colour="gray") +
  geom_pointrange(aes(y=est_posterior,x=index+.4,ymin=ub_posterior,ymax=lb_posterior),
    fill='black',color="black",size=.3,shape=20) + 
  geom_pointrange(aes(y=est_posterior,x=index+.4,ymin=lb2_posterior,ymax=ub2_posterior),
    linewidth=1,fill='black',color="black",size=.3,shape=20) +
  geom_pointrange(aes(y=est_prior,x=index-.4,ymin=ub_prior,ymax=lb_prior),
    fill='darkgray',color="darkgray",size=.3,shape=20) + 
  geom_pointrange(aes(y=est_prior,x=index-.4,ymin=lb2_prior,ymax=ub2_prior),
    linewidth=1,fill='darkgray',color="darkgray",size=.3,shape=20) +
  scale_color_manual(values=c("black", "black")) +
  scale_linetype_manual(values=c("dotted", "dashed")) +
  annotate("text", 
    x = c(13,25,31,12,13.5), 
    y = c(4,4,4,3.25,2.6),
    label = c("Wave 1","Wave 2","Wave 3","Prior","Posterior"),
    color = c(rep("darkgray",4),rep("black",1))) +
#  labs(color='Real inflation',linetype='Real inflation') +
  theme_bw() +
  theme(axis.text.x=element_text(angle=45,hjust=1,vjust=1),
    legend.title=element_blank())
dev.off() 

panelData %>% filter(wave==14) %>% ungroup() %>%
  summarise(mean=mean(prior,na.rm=T),sd=sd(prior,na.rm=T))

panelData %>% filter(wave==23) %>% ungroup() %>%
  summarise(mean=mean(prior,na.rm=T),sd=sd(prior,na.rm=T))

panelData %>% filter(wave==14|wave==20|wave==23) %>% group_by(wave) %>%
  summarise(mean=mean(posterior,na.rm=T),sd=sd(posterior,na.rm=T))

#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
# 4 Results
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
# 4.1 Information effects ----
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
# Clear vs vague information ----
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
# Figure 2: ----
# Respondents' Reported Prior and Posterior Inflation Expectations by First 
# Information Treatment and Waves
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
o1 <- panelData %>% 
  pivot_longer(cols=c(prior,posterior)) %>%
  mutate(cat=factor(
    ifelse(wave==14&name=='prior','Prior, Wave 1',
    ifelse(wave==14&name=='posterior','Posterior, Wave 1',
    ifelse(wave==20&name=='posterior','Posterior, Wave 2',
    ifelse(wave==23&name=='posterior','Posterior, Wave 3',NA)))),
    levels=c('Prior, Wave 1','Posterior, Wave 1','Posterior, Wave 2',
      'Posterior, Wave 3')),
    anchorTreat1=factor(recode(anchorTreat1,
      'Clear'='Clear information','Vague'='Vague information')),
      value=round(value)) %>%
  filter(!is.na(cat)&!is.na(value)&!is.na(anchorTreat1)) 

pdf("figure2.pdf",width=5,height=4)
o1 %>%
  group_by(anchorTreat1,cat,value) %>%
  summarise(n=n()) %>%
  mutate(N=max(cumsum(n)),freq=n/N) %>%
  ggplot(aes(y=freq,x=value,fill=anchorTreat1)) +
  geom_col(position=position_dodge(width=1)) +
  facet_wrap(~cat,ncol=2) + 
  scale_fill_manual(values=c('black','gray')) +
  scale_y_continuous(limits=c(0,.42),breaks=seq(0,.4,.1),labels=seq(-0,.4,.1)) +
  scale_x_continuous(breaks=seq(-1,10,1),labels=seq(-1,10,1)) +
  labs(y='Share of respondents',x='Inflation expectation') + 
  theme_bw() +
  theme(legend.position='none')
dev.off()

# Statistics in text
panelData %>% 
  filter(wave==14) %>% 
  group_by(anchorTreat1) %>%
  summarise(
    meanPrior=mean(prior,na.rm=T),
    meanPosterior=mean(posterior,na.rm=T),
    varPrior=var(prior,na.rm=T),
    varPosterior=var(posterior,na.rm=T))

t.test(prior ~ anchorTreat1,subset(panelData,wave==14), 
  alternative = "two.sided")
wilcox.test(prior ~ anchorTreat1,subset(panelData,wave==14), 
  alternative = "two.sided")
t.test(posterior ~ anchorTreat1,subset(panelData,wave==14), 
  alternative = "two.sided")
wilcox.test(posterior ~ anchorTreat1,subset(panelData,wave==14), 
  alternative = "two.sided")

var.test(prior ~ anchorTreat1,subset(panelData,wave==14), 
  alternative = "two.sided")
var.test(posterior ~ anchorTreat1,subset(panelData,wave==14), 
  alternative = "two.sided")

o2 <- panelData %>% filter(wave==14) %>% 
  select(prior,posterior,anchorTreat1,id_g) %>%
  pivot_longer(cols=c(prior,posterior)) %>%
  mutate(name=factor(name,levels=c('prior','posterior')))

o2 %>% 
  mutate(anchorTreat1=factor(anchorTreat1)) %>%
  lm_robust(value~name*relevel(anchorTreat1,ref='Vague'),
            clusters=id_g,data=.) %>% 
  summary()

var.test(value ~ name,subset(o2,anchorTreat1=='Clear'), 
  alternative = "two.sided")
var.test(value ~ name,subset(o2,anchorTreat1=='Vague'), 
  alternative = "two.sided")

# account for clustering
levenetestClust(value~name,id=id_g,data=subset(o2,anchorTreat1=='Clear'))
levenetestClust(value~name,id=id_g,data=subset(o2,anchorTreat1=='Vague'))

panelData %>% filter(wave==14) %>% group_by(anchorTreat1) %>%
  summarise(varPrior=var(prior,na.rm=T),
    varPosterior=var(posterior,na.rm=T))

# Wave 2 and 3 posterior
t.test(value ~ anchorTreat1,subset(o1,cat=='Posterior, Wave 2'), 
  alternative = "two.sided")
wilcox.test(value ~ anchorTreat1,subset(o1,cat=='Posterior, Wave 2'), 
  alternative = "two.sided")
t.test(value ~ anchorTreat1,subset(o1,cat=='Posterior, Wave 3'), 
  alternative = "two.sided")
wilcox.test(value ~ anchorTreat1,subset(o1,cat=='Posterior, Wave 3'), 
  alternative = "two.sided")
o1 %>% filter(cat=='Posterior, Wave 2'|cat=='Posterior, Wave 3') %>% 
  group_by(anchorTreat1,cat) %>%
  summarise(meanPosterior=mean(value,na.rm=T))

var.test(value ~ anchorTreat1,subset(o1,cat=='Posterior, Wave 2'),  
  alternative = "two.sided")
var.test(value ~ anchorTreat1,subset(o1,cat=='Posterior, Wave 3'), 
  alternative = "two.sided")

o3 <- o1 %>% 
  filter(cat=='Prior, Wave 1'|cat=='Posterior, Wave 2') %>%
  droplevels()
var.test(value~cat,subset(o3,anchorTreat1=='Clear information'), 
  alternative = "two.sided")
var.test(value~cat,subset(o3,anchorTreat1=='Vague information'), 
  alternative = "two.sided")

o4 <- o1 %>% 
  filter(cat=='Prior, Wave 1'|cat=='Posterior, Wave 3') %>%
  droplevels()
var.test(value~cat,subset(o4,anchorTreat1=='Clear information'), 
  alternative = "two.sided")
var.test(value~cat,subset(o4,anchorTreat1=='Vague information'), 
  alternative = "two.sided")

# account for clustering
levenetestClust(value~cat,id=id_g,data=subset(o3,anchorTreat1=='Clear information'))
levenetestClust(value~cat,id=id_g,data=subset(o3,anchorTreat1=='Vague information'))
levenetestClust(value~cat,id=id_g,data=subset(o4,anchorTreat1=='Clear information'))
levenetestClust(value~cat,id=id_g,data=subset(o4,anchorTreat1=='Vague information'))

#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
# Table 2: ----
# Linear Regression of Posterior Inflation Expectation in Wave 1, 2, and 3 on 
# First Information Treatment Indicator, Prior Inflation Expectation, Covariates, 
# and their Interactions.
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
o <- panelData %>% 
  group_by(id_g) %>%
  mutate(prior=ifelse(wave==14,prior,NA),
    prior=mean(prior,na.rm=T),
    anchorTreat1=factor(anchorTreat1,levels=c('Vague','Clear'))) %>%
  ungroup()

m1 <- o %>% filter(wave==14) %>%
  lm_robust(posterior~anchorTreat1, data=.)
m2 <- o %>% filter(wave==20) %>%
  lm_robust(posterior~anchorTreat1, data=.)
m3 <- o %>% filter(wave==23) %>%
  lm_robust(posterior~anchorTreat1, data=.)
m4 <- o %>% filter(wave==14) %>%
  lm_robust(posterior~anchorTreat1*prior, data=.)
m5 <- o %>% filter(wave==20) %>%
  lm_robust(posterior~anchorTreat1*prior, data=.)
m6 <- o %>% filter(wave==23) %>%
  lm_robust(posterior~anchorTreat1*prior, data=.)
m7 <- o %>% filter(wave==14) %>%
  lm_robust(posterior~anchorTreat1*(prior+newsConBusiness+newsCon+evaluateECB), data=.)
m8 <- o %>% filter(wave==20) %>%
  lm_robust(posterior~anchorTreat1*(prior+newsConBusiness+newsCon+evaluateECB), data=.)
m9 <- o %>% filter(wave==23) %>%
  lm_robust(posterior~anchorTreat1*(prior+newsConBusiness+newsCon+evaluateECB), data=.)

texreg(list(m1,m2,m3,m4,m5,m6,m7,m8,m9),
       digits=3,single.row=F,include.ci=F,stars=c(.1,.05,.01),
       reorder.coef=c(2,3,4,5,6,7,8,9,10,1),
       custom.model.name=c('Wave 1','Wave 2','Wave 3','Wave 1','Wave 2','Wave 3',
                           'Wave 1','Wave 2','Wave 3'),
       custom.coef.names=c('Constant','Clear information','Prior',
                           'Clear information x prior','Business news consumption','News consumption',
                           'Positive evaluation of ECB','Clear information x Business news consumption',
                           'Clear information x News consumption',
                           'Clear information x Positive evaluation of ECB'),
       table=F,
       file="table2.tex") 

#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
# Short vs long information ----
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
# Figure 3: ----
# Marginal Effect of Respondents' Reported Prior Inflation Expectations (Wave 1) 
# on Reported Posterior Inflation Expectations (Wave 2 and 3) by Second Wave 
# Information Treatment.
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
o <- panelData %>% 
  group_by(id_g) %>%
  mutate(prior=ifelse(wave==14,prior,NA),
    prior=mean(prior,na.rm=T)) %>%
  ungroup() %>%
  mutate(anchorTreat2Bin=factor(recode(anchorTreat2,
      'Clear, long'="Long",'Clear, short'="Short",
      'Vague, long'="Long",'Vague, short'="Short"),
      levels=c('Long','Short')),
    anchorTreat2=factor(anchorTreat2,
      levels=c('Clear, short','Clear, long','Vague, short','Vague, long'))) 

r <- rbind(
  # Binary
  lm_robust(posterior~prior+newsConBusiness+newsCon+evaluateECB, 
      data=o %>% filter(wave==20&anchorTreat2Bin=="Short")) %>% margins() %>% 
    summary() %>% filter(factor=="prior") %>% select(AME,lower,upper) %>%
    mutate(t='Short',wave='Wave 2'),
  lm_robust(posterior~prior+newsConBusiness+newsCon+evaluateECB, 
      data=o %>% filter(wave==20&anchorTreat2Bin=="Long")) %>% margins() %>%
    summary() %>% filter(factor=="prior") %>% select(AME,lower,upper) %>%
    mutate(t='Long',wave='Wave 2'),
  lm_robust(posterior~prior+newsConBusiness+newsCon+evaluateECB, 
      data=o %>% filter(wave==23&anchorTreat2Bin=="Short")) %>% margins() %>% 
    summary() %>% filter(factor=="prior") %>% select(AME,lower,upper) %>%
    mutate(t='Short',wave='Wave 3'),
  lm_robust(posterior~prior+newsConBusiness+newsCon+evaluateECB, 
      data=o %>% filter(wave==23&anchorTreat2Bin=="Long")) %>% margins() %>%
    summary() %>% filter(factor=="prior") %>% select(AME,lower,upper) %>%
    mutate(t='Long',wave='Wave 3'),
  # 4-items
  lm_robust(posterior~prior+newsConBusiness+newsCon+evaluateECB, 
      data=o %>% filter(wave==20&anchorTreat2=="Clear, short")) %>% margins() %>% 
    summary() %>% filter(factor=="prior") %>% select(AME,lower,upper) %>%
    mutate(t='Clear, short',wave='Wave 2'),
  lm_robust(posterior~prior+newsConBusiness+newsCon+evaluateECB, 
      data=o %>% filter(wave==20&anchorTreat2=="Clear, long")) %>% margins() %>%
    summary() %>% filter(factor=="prior") %>% select(AME,lower,upper) %>%
    mutate(t='Clear, long',wave='Wave 2'),
  lm_robust(posterior~prior+newsConBusiness+newsCon+evaluateECB, 
      data=o %>% filter(wave==20&anchorTreat2=="Vague, short")) %>% margins() %>% 
    summary() %>% filter(factor=="prior") %>% select(AME,lower,upper) %>%
    mutate(t='Vague, short',wave='Wave 2'),
  lm_robust(posterior~prior+newsConBusiness+newsCon+evaluateECB, 
      data=o %>% filter(wave==20&anchorTreat2=="Vague, long")) %>% margins() %>%
    summary() %>% filter(factor=="prior") %>% select(AME,lower,upper) %>%
    mutate(t='Vague, long',wave='Wave 2'),
  lm_robust(posterior~prior+newsConBusiness+newsCon+evaluateECB, 
      data=o %>% filter(wave==23&anchorTreat2=="Clear, short")) %>% margins() %>% 
    summary() %>% filter(factor=="prior") %>% select(AME,lower,upper) %>%
    mutate(t='Clear, short',wave='Wave 3'),
  lm_robust(posterior~prior+newsConBusiness+newsCon+evaluateECB, 
      data=o %>% filter(wave==23&anchorTreat2=="Clear, long")) %>% margins() %>%
    summary() %>% filter(factor=="prior") %>% select(AME,lower,upper) %>%
    mutate(t='Clear, long',wave='Wave 3'),
  lm_robust(posterior~prior+newsConBusiness+newsCon+evaluateECB, 
      data=o %>% filter(wave==23&anchorTreat2=="Vague, short")) %>% margins() %>% 
    summary() %>% filter(factor=="prior") %>% select(AME,lower,upper) %>%
    mutate(t='Vague, short',wave='Wave 3'),
  lm_robust(posterior~prior+newsConBusiness+newsCon+evaluateECB, 
      data=o %>% filter(wave==23&anchorTreat2=="Vague, long")) %>% margins() %>%
    summary() %>% filter(factor=="prior") %>% select(AME,lower,upper) %>%
    mutate(t='Vague, long',wave='Wave 3'))

pdf("figure3.pdf",height=3)
r %>%
  mutate(facet=ifelse(t=='Long'|t=='Short',1,0),
    t=factor(t,levels=c('Clear, short','Clear, long','Vague, short',
      'Vague, long','Short','Long'))) %>%
  ggplot() +
  facet_grid(~facet,scales='free') +
  geom_line(aes(y=AME,x=t,group=wave,linetype=wave,color=wave),
    position=position_dodge2(width=.3)) + 
  geom_pointrange(aes(y=AME,x=t,ymin=lower,ymax=upper,color=wave,fill=wave),
    shape=21,position=position_dodge2(width=.3)) + 
  scale_color_manual(values=c('black','black')) +
  scale_fill_manual(values=c('black','white')) +
  labs(y='Marginal effect of prior',x='') + 
  theme_bw(base_size = 11) +
  theme(legend.position='bottom',legend.title=element_blank(),
    strip.background=element_blank(),strip.text=element_blank(),
    axis.text.x=element_text(angle=45,hjust=1,vjust=1))
dev.off()

# Statistics in the text
o %>% filter(wave==20) %>%
  lm_robust(posterior~anchorTreat2Bin*(prior+newsConBusiness+newsCon+evaluateECB), 
    data=.) %>% summary()
o %>% filter(wave==23) %>%
  lm_robust(posterior~anchorTreat2Bin*(prior+newsConBusiness+newsCon+evaluateECB), 
    data=.) %>% summary()
o %>% filter(wave==20) %>%
  lm_robust(posterior~anchorTreat2*(prior+newsConBusiness+newsCon+evaluateECB), 
    data=.) %>% summary()
o %>% filter(wave==23) %>%
  lm_robust(posterior~anchorTreat2*(prior+newsConBusiness+newsCon+evaluateECB), 
    data=.) %>% summary()

#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
# Repeated vs single exposure to information ----
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
# Figure 4: ----
# Respondents' Reported Prior and Posterior Inflation Expectations by First 
# Information Treatment and Waves
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
o0 <- panelData %>% 
  filter(wave==14|wave==20|wave==23) %>%
  mutate(
    anchorTreat2=factor(recode(anchorTreat2,
      'Clear, long'="Clear",'Clear, short'="Clear",
      'Vague, long'="Vague",'Vague, short'="Vague")),
    anchorTreat=paste(anchorTreat1,anchorTreat2,sep=', '),
    repeatedTreat=factor(
      ifelse(anchorTreat=='Clear, Clear','Clear twice',
      ifelse(anchorTreat=='Clear, Vague','First clear then vague',       
      ifelse(anchorTreat=='Vague, Clear','First vague then clear',
      ifelse(anchorTreat=='Vague, Vague','Vague twice',
      ifelse(anchorTreat=='Clear, NA','Clear only first',
      ifelse(anchorTreat=='NA, Clear','Clear only second',
      ifelse(anchorTreat=='Vague, NA','Vague only first',
      ifelse(anchorTreat=='NA, Vague','Vague only second',NA)))))))),
      levels=c('Clear twice','Vague twice','First clear then vague',
        'First vague then clear','Clear only first',
        'Clear only second','Vague only first','Vague only second'))) %>%
  filter(!is.na(repeatedTreat)) %>%
  mutate(repeatedTreatType=
      ifelse(repeatedTreat=='Clear twice'|repeatedTreat=='Vague twice','Repeated',
      ifelse(repeatedTreat=='First clear then vague'|
        repeatedTreat=='First vague then clear','Mixed','Once')),
    posterior2=ifelse(wave==20,posterior,NA),
    posterior3=ifelse(wave==23,posterior,NA),
    prior=ifelse(wave==14,prior,NA)) 

o1 <- o0 %>%
  select(id_g,repeatedTreat,repeatedTreatType,prior,posterior2,posterior3,wave,
    newsConBusiness,newsCon,evaluateECB) %>%
  group_by(id_g) %>%
  mutate(posterior2=mean(posterior2,na.rm=T),
    posterior3=mean(posterior3,na.rm=T),
    prior=mean(prior,na.rm=T)) %>% 
  ungroup() %>%
  distinct()

r <- rbind(
  o1 %>%
    group_by(repeatedTreatType) %>%
    do(lm_robust(prior~repeatedTreat-1,data=.) %>% tidy()) %>%
    filter(term!='(Intercept)') %>%
    mutate(repeatedTreat=str_remove(term,'repeatedTreat'),variable="Prior"),
  o1 %>%
    group_by(repeatedTreatType) %>%
    do(lm_robust(posterior2~repeatedTreat-1,data=.) %>% tidy()) %>%
    filter(term!='(Intercept)') %>%
    mutate(repeatedTreat=str_remove(term,'repeatedTreat'),variable="Posterior, Wave 2"),
  o1 %>%
    group_by(repeatedTreatType) %>%
    do(lm_robust(posterior3~repeatedTreat-1,data=.) %>% tidy()) %>%
    filter(term!='(Intercept)') %>%
    mutate(repeatedTreat=str_remove(term,'repeatedTreat'),variable="Posterior, Wave 3")) %>%
  mutate(
    variable=factor(variable,levels=c('Prior','Posterior, Wave 2','Posterior, Wave 3')))

pdf("figure4.pdf",height=3)
r %>% 
  filter(repeatedTreatType!="Once") %>%
  ggplot(aes(y=estimate,x=repeatedTreat,ymin=conf.low,ymax=conf.high,color=variable,
             fill=variable)) +
  geom_pointrange(position=position_dodge(width=.5),shape=21) +
  facet_grid(repeatedTreatType~.,scale='free') + 
  coord_flip() +
  scale_color_manual(values=c('black','black','gray')) +
  scale_fill_manual(values=c('black','white','gray')) +
  labs(y='Inflation expectation',x='') + 
  theme_bw() +
  theme(legend.position='bottom',legend.title=element_blank())
dev.off()

#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
# 4.2 Information effects by approval of the ECB ----
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
# Figure 5: ----
# Marginal Effect of Priors on Posterior Inflation Expectation by Approval of 
# ECB performance, first wave information treatment, and waves.
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
o <- panelData %>% 
  group_by(id_g) %>%
  mutate(prior=ifelse(wave==14,prior,NA),
    prior=mean(prior,na.rm=T),
    anchorTreat1=factor(anchorTreat1,levels=c('Vague','Clear'))) %>%
  ungroup()

r <- rbind(
  lm_robust(posterior~prior*(evaluateECB+newsConBusiness+newsCon), 
      data=o %>% filter(wave==14&anchorTreat1=="Clear")) %>% 
    margins(variables='prior',at=list(evaluateECB=1:5)) %>% 
    summary() %>% filter(factor=="prior") %>% select(AME,lower,upper,evaluateECB) %>%
    mutate(t='Clear information',wave='Wave 1'),
  lm_robust(posterior~prior*(evaluateECB+newsConBusiness+newsCon), 
      data=o %>% filter(wave==14&anchorTreat1=="Vague")) %>% 
    margins(variables='prior',at=list(evaluateECB=1:5)) %>% 
    summary() %>% filter(factor=="prior") %>% select(AME,lower,upper,evaluateECB) %>%
    mutate(t='Vague information',wave='Wave 1'),
  lm_robust(posterior~prior*(evaluateECB+newsConBusiness+newsCon), 
      data=o %>% filter(wave==20&anchorTreat1=="Clear")) %>% 
    margins(variables='prior',at=list(evaluateECB=1:5)) %>% 
    summary() %>% filter(factor=="prior") %>% select(AME,lower,upper,evaluateECB) %>%
    mutate(t='Clear information',wave='Wave 2'),
  lm_robust(posterior~prior*(evaluateECB+newsConBusiness+newsCon), 
      data=o %>% filter(wave==20&anchorTreat1=="Vague")) %>% 
    margins(variables='prior',at=list(evaluateECB=1:5)) %>% 
    summary() %>% filter(factor=="prior") %>% select(AME,lower,upper,evaluateECB) %>%
    mutate(t='Vague information',wave='Wave 2'),
  lm_robust(posterior~prior*(evaluateECB+newsConBusiness+newsCon),  
      data=o %>% filter(wave==23&anchorTreat1=="Clear")) %>% 
    margins(variables='prior',at=list(evaluateECB=1:5)) %>% 
    summary() %>% filter(factor=="prior") %>% select(AME,lower,upper,evaluateECB) %>%
    mutate(t='Clear information',wave='Wave 3'),
  lm_robust(posterior~prior*(evaluateECB+newsConBusiness+newsCon), 
      data=o %>% filter(wave==23&anchorTreat1=="Vague")) %>% 
    margins(variables='prior',at=list(evaluateECB=1:5)) %>% 
    summary() %>% filter(factor=="prior") %>% select(AME,lower,upper,evaluateECB) %>%
    mutate(t='Vague information',wave='Wave 3'))

pdf("figure5.pdf",height=3)
r %>%
  ggplot() +
  geom_line(aes(y=AME,x=evaluateECB,group=wave,linetype=wave,color=wave),
    position=position_dodge2(width=.5)) + 
  geom_pointrange(aes(y=AME,x=evaluateECB,ymin=lower,ymax=upper,color=wave,fill=wave),
    shape=21,position=position_dodge2(width=.5)) + 
  facet_grid(~t) +
  scale_color_manual(values=c('black','black','darkgray')) +
  scale_fill_manual(values=c('black','white','darkgray')) +
  labs(y='Marginal effect of prior',x='Approval of ECB performance') + 
  theme_bw(base_size=11) +
  theme(legend.position='bottom',legend.title=element_blank())
dev.off()

#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
# Figure 6: ----
# Marginal Effect of Priors on Posterior Inflation Expectation by Attitudes 
# towards EU Integration, first wave information treatment, and waves.
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
o <- panelData %>% 
  group_by(id_g) %>%
  mutate(prior=ifelse(wave==14,prior,NA),
    prior=mean(prior,na.rm=T),
    anchorTreat1=factor(anchorTreat1,levels=c('Vague','Clear')),
    euIntegration=ifelse(euIntegration<=-90,NA,euIntegration)) %>%
  ungroup()

r <- rbind(
  lm_robust(posterior~prior*(euIntegration+newsConBusiness+newsCon), 
      data=o %>% filter(wave==14&anchorTreat1=="Clear")) %>% 
    margins(variables='prior',at=list(euIntegration=0:10)) %>% 
    summary() %>% filter(factor=="prior") %>% select(AME,lower,upper,euIntegration) %>%
    mutate(t='Clear information',wave='Wave 1'),
  lm_robust(posterior~prior*(euIntegration+newsConBusiness+newsCon), 
      data=o %>% filter(wave==14&anchorTreat1=="Vague")) %>% 
    margins(variables='prior',at=list(euIntegration=0:10)) %>% 
    summary() %>% filter(factor=="prior") %>% select(AME,lower,upper,euIntegration) %>%
    mutate(t='Vague information',wave='Wave 1'),
  lm_robust(posterior~prior*(euIntegration+newsConBusiness+newsCon), 
      data=o %>% filter(wave==20&anchorTreat1=="Clear")) %>% 
    margins(variables='prior',at=list(euIntegration=0:10)) %>% 
    summary() %>% filter(factor=="prior") %>% select(AME,lower,upper,euIntegration) %>%
    mutate(t='Clear information',wave='Wave 2'),
  lm_robust(posterior~prior*(euIntegration+newsConBusiness+newsCon), 
      data=o %>% filter(wave==20&anchorTreat1=="Vague")) %>% 
    margins(variables='prior',at=list(euIntegration=0:10)) %>% 
    summary() %>% filter(factor=="prior") %>% select(AME,lower,upper,euIntegration) %>%
    mutate(t='Vague information',wave='Wave 2'),
  lm_robust(posterior~prior*(euIntegration+newsConBusiness+newsCon),  
      data=o %>% filter(wave==23&anchorTreat1=="Clear")) %>% 
    margins(variables='prior',at=list(euIntegration=0:10)) %>% 
    summary() %>% filter(factor=="prior") %>% select(AME,lower,upper,euIntegration) %>%
    mutate(t='Clear information',wave='Wave 3'),
  lm_robust(posterior~prior*(euIntegration+newsConBusiness+newsCon), 
      data=o %>% filter(wave==23&anchorTreat1=="Vague")) %>% 
    margins(variables='prior',at=list(euIntegration=0:10)) %>% 
    summary() %>% filter(factor=="prior") %>% select(AME,lower,upper,euIntegration) %>%
    mutate(t='Vague information',wave='Wave 3'))

pdf("figure6.pdf",height=3)
r %>%
  ggplot() +
  geom_line(aes(y=AME,x=euIntegration,group=wave,linetype=wave,color=wave),
    position=position_dodge2(width=.75)) + 
  geom_pointrange(aes(y=AME,x=euIntegration,ymin=lower,ymax=upper,color=wave,
    fill=wave),shape=21,position=position_dodge2(width=.75)) + 
  facet_grid(~t) +
  scale_color_manual(values=c('black','black','darkgray')) +
  scale_fill_manual(values=c('black','white','darkgray')) +
  scale_x_continuous(breaks=seq(0,10,1),labels=seq(0,10,1)) + 
  labs(y='Marginal effect of prior',x='Support of EU integration') + 
  theme_bw(base_size = 11) +
  theme(legend.position='bottom',legend.title=element_blank())
dev.off()

panelData %>%
  select(id_g,evaluateECB,euIntegration) %>%
  distinct() %$%
  cor.test(evaluateECB,euIntegration)

#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
# Figure 7: ----
# Marginal Effect of Priors on Posterior Inflation Expectation by Left-Right 
# Self-Placement, first wave information treatment, and waves.
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
o <- panelData %>% 
  group_by(id_g) %>%
  mutate(prior=ifelse(wave==14,prior,NA),
    prior=mean(prior,na.rm=T),
    anchorTreat1=factor(anchorTreat1,levels=c('Vague','Clear'))) %>%
  ungroup()

r <- rbind(
  lm_robust(posterior~prior*(leftRight+newsConBusiness+newsCon), 
      data=o %>% filter(wave==14&anchorTreat1=="Clear")) %>% 
    margins(variables='prior',at=list(leftRight=1:11)) %>% 
    summary() %>% filter(factor=="prior") %>% select(AME,lower,upper,leftRight) %>%
    mutate(t='Clear information',wave='Wave 1'),
  lm_robust(posterior~prior*(leftRight+newsConBusiness+newsCon), 
      data=o %>% filter(wave==14&anchorTreat1=="Vague")) %>% 
    margins(variables='prior',at=list(leftRight=1:11)) %>% 
    summary() %>% filter(factor=="prior") %>% select(AME,lower,upper,leftRight) %>%
    mutate(t='Vague information',wave='Wave 1'),
  lm_robust(posterior~prior*(leftRight+newsConBusiness+newsCon), 
      data=o %>% filter(wave==20&anchorTreat1=="Clear")) %>% 
    margins(variables='prior',at=list(leftRight=1:11)) %>% 
    summary() %>% filter(factor=="prior") %>% select(AME,lower,upper,leftRight) %>%
    mutate(t='Clear information',wave='Wave 2'),
  lm_robust(posterior~prior*(leftRight+newsConBusiness+newsCon), 
      data=o %>% filter(wave==20&anchorTreat1=="Vague")) %>% 
    margins(variables='prior',at=list(leftRight=1:11)) %>% 
    summary() %>% filter(factor=="prior") %>% select(AME,lower,upper,leftRight) %>%
    mutate(t='Vague information',wave='Wave 2'),
  lm_robust(posterior~prior*(leftRight+newsConBusiness+newsCon),  
      data=o %>% filter(wave==23&anchorTreat1=="Clear")) %>% 
    margins(variables='prior',at=list(leftRight=1:11)) %>% 
    summary() %>% filter(factor=="prior") %>% select(AME,lower,upper,leftRight) %>%
    mutate(t='Clear information',wave='Wave 3'),
  lm_robust(posterior~prior*(leftRight+newsConBusiness+newsCon), 
      data=o %>% filter(wave==23&anchorTreat1=="Vague")) %>% 
    margins(variables='prior',at=list(leftRight=1:11)) %>% 
    summary() %>% filter(factor=="prior") %>% select(AME,lower,upper,leftRight) %>%
    mutate(t='Vague information',wave='Wave 3'))

pdf("figure7.pdf",height=3)
r %>%
  ggplot() +
  geom_line(aes(y=AME,x=leftRight,group=wave,linetype=wave,color=wave),
    position=position_dodge2(width=.5)) + 
  geom_pointrange(aes(y=AME,x=leftRight,ymin=lower,ymax=upper,color=wave,
    fill=wave),shape=21,position=position_dodge2(width=.5)) + 
  facet_grid(~t) +
  scale_color_manual(values=c('black','black','darkgray')) +
  scale_fill_manual(values=c('black','white','darkgray')) +
  scale_x_continuous(breaks=seq(0,11,1),labels=seq(0,11,1)) + 
  labs(y='Marginal effect of prior',x='Left-right self-placement') + 
  theme_bw(base_size = 11) +
  theme(legend.position='bottom',legend.title=element_blank())
dev.off()

#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
# 5 Alternative Mechanisms ----
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
# Figure 8: ----
# Marginal Effect of Priors on Posterior Inflation Expectation by Business News
# Consumption, First Wave Information Treatment, and Waves.
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
o <- panelData %>% 
  group_by(id_g) %>%
  mutate(prior=ifelse(wave==14,prior,NA),
    prior=mean(prior,na.rm=T),
    anchorTreat1=factor(anchorTreat1,levels=c('Vague','Clear'))) %>%
  ungroup()

r <- rbind(
  lm_robust(posterior~prior*(evaluateECB+newsConBusiness+newsCon), 
      data=o %>% filter(wave==14&anchorTreat1=="Clear")) %>% 
    margins(variables='prior',at=list(newsConBusiness=1:7)) %>% 
    summary() %>% filter(factor=="prior") %>% select(AME,lower,upper,newsConBusiness) %>%
    mutate(t='Clear information',wave='Wave 1'),
  lm_robust(posterior~prior*(evaluateECB+newsConBusiness+newsCon), 
      data=o %>% filter(wave==14&anchorTreat1=="Vague")) %>% 
    margins(variables='prior',at=list(newsConBusiness=1:7)) %>% 
    summary() %>% filter(factor=="prior") %>% select(AME,lower,upper,newsConBusiness) %>%
    mutate(t='Vague information',wave='Wave 1'),
  lm_robust(posterior~prior*(evaluateECB+newsConBusiness+newsCon), 
      data=o %>% filter(wave==20&anchorTreat1=="Clear")) %>% 
    margins(variables='prior',at=list(newsConBusiness=1:7)) %>% 
    summary() %>% filter(factor=="prior") %>% select(AME,lower,upper,newsConBusiness) %>%
    mutate(t='Clear information',wave='Wave 2'),
  lm_robust(posterior~prior*(evaluateECB+newsConBusiness+newsCon), 
      data=o %>% filter(wave==20&anchorTreat1=="Vague")) %>% 
    margins(variables='prior',at=list(newsConBusiness=1:7)) %>% 
    summary() %>% filter(factor=="prior") %>% select(AME,lower,upper,newsConBusiness) %>%
    mutate(t='Vague information',wave='Wave 2'),
  lm_robust(posterior~prior*(evaluateECB+newsConBusiness+newsCon),  
      data=o %>% filter(wave==23&anchorTreat1=="Clear")) %>% 
    margins(variables='prior',at=list(newsConBusiness=1:7)) %>% 
    summary() %>% filter(factor=="prior") %>% select(AME,lower,upper,newsConBusiness) %>%
    mutate(t='Clear information',wave='Wave 3'),
  lm_robust(posterior~prior*(evaluateECB+newsConBusiness+newsCon), 
      data=o %>% filter(wave==23&anchorTreat1=="Vague")) %>% 
    margins(variables='prior',at=list(newsConBusiness=1:7)) %>%  
    summary() %>% filter(factor=="prior") %>% select(AME,lower,upper,newsConBusiness) %>%
    mutate(t='Vague information',wave='Wave 3'))

pdf("figure8.pdf",height=3)
r %>%
  ggplot() +
  geom_line(aes(y=AME,x=newsConBusiness,group=wave,linetype=wave,color=wave),
    position=position_dodge2(width=.5)) + 
  geom_pointrange(aes(y=AME,x=newsConBusiness,ymin=lower,ymax=upper,color=wave,
    fill=wave),shape=21,position=position_dodge2(width=.5)) + 
  facet_grid(~t) +
  scale_color_manual(values=c('black','black','darkgray')) +
  scale_fill_manual(values=c('black','white','darkgray')) +
  scale_x_continuous(breaks=seq(1,7,1),labels=seq(1,7,1)) +
  labs(y='Marginal effect of prior',x='Business news consumption') + 
  theme_bw(base_size = 11) +
  theme(legend.position='bottom',legend.title=element_blank())
dev.off()

#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
# Figure 9: ----
# Marginal Effect of Priors on Posterior Inflation Expectation by policy 
# congruence, first wave information treatment, and waves.
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
o <- panelData %>% 
  group_by(id_g) %>%
  mutate(prior=ifelse(wave==14,prior,NA),
    prior=mean(prior,na.rm=T),
    policy=mean(policy,na.rm=T),
    anchorTreat1=factor(anchorTreat1,levels=c('Vague','Clear'))) %>%
  ungroup()

r <- rbind(
  lm_robust(posterior~prior*(policy+newsConBusiness+newsCon), 
      data=o %>% filter(wave==14&anchorTreat1=="Clear")) %>% 
    margins(variables='prior',at=list(policy=0:9)) %>% 
    summary() %>% filter(factor=="prior") %>% select(AME,lower,upper,policy) %>%
    mutate(t='Clear information',wave='Wave 1'),
  lm_robust(posterior~prior*(policy+newsConBusiness+newsCon), 
      data=o %>% filter(wave==14&anchorTreat1=="Vague")) %>% 
    margins(variables='prior',at=list(policy=0:9)) %>% 
    summary() %>% filter(factor=="prior") %>% select(AME,lower,upper,policy) %>%
    mutate(t='Vague information',wave='Wave 1'),
  lm_robust(posterior~prior*(policy+newsConBusiness+newsCon), 
      data=o %>% filter(wave==20&anchorTreat1=="Clear")) %>% 
    margins(variables='prior',at=list(policy=0:9)) %>% 
    summary() %>% filter(factor=="prior") %>% select(AME,lower,upper,policy) %>%
    mutate(t='Clear information',wave='Wave 2'),
  lm_robust(posterior~prior*(policy+newsConBusiness+newsCon), 
      data=o %>% filter(wave==20&anchorTreat1=="Vague")) %>% 
    margins(variables='prior',at=list(policy=0:9)) %>% 
    summary() %>% filter(factor=="prior") %>% select(AME,lower,upper,policy) %>%
    mutate(t='Vague information',wave='Wave 2'),
  lm_robust(posterior~prior*(policy+newsConBusiness+newsCon),  
      data=o %>% filter(wave==23&anchorTreat1=="Clear")) %>% 
    margins(variables='prior',at=list(policy=0:9)) %>% 
    summary() %>% filter(factor=="prior") %>% select(AME,lower,upper,policy) %>%
    mutate(t='Clear information',wave='Wave 3'),
  lm_robust(posterior~prior*(policy+newsConBusiness+newsCon), 
      data=o %>% filter(wave==23&anchorTreat1=="Vague")) %>% 
    margins(variables='prior',at=list(policy=0:9)) %>% 
    summary() %>% filter(factor=="prior") %>% select(AME,lower,upper,policy) %>%
    mutate(t='Vague information',wave='Wave 3'))

pdf("figure9.pdf",height=4)
r %>%
  ggplot() +
  geom_line(aes(y=AME,x=policy,group=wave,linetype=wave,color=wave),
    position=position_dodge2(width=.5)) + 
  geom_pointrange(aes(y=AME,x=policy,ymin=lower,ymax=upper,color=wave,fill=wave),
    shape=21,position=position_dodge2(width=.5)) + 
  facet_grid(~t) +
  scale_color_manual(values=c('black','black','darkgray')) +
  scale_fill_manual(values=c('black','white','darkgray')) +
  labs(y='Marginal effect of prior',
       x='Inflation preference difference from ECB 2% target') + 
  theme_bw(base_size=11) +
  theme(legend.position='bottom',legend.title=element_blank())
dev.off()

#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
# A Experimental design appendix ----
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
# A.3 Wave and treatment statistics ----
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
# Table A.2: ----
# Wave and treatment statistics
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
t1 <- panelData %>%
  filter(wave==14) %>%
  group_by(wave,anchorTreat1) %>%
  summarise(n=n()) %>%
  mutate(N=max(cumsum(n)),relFreq=n/N) %>%
  ungroup() %>%
  select(anchorTreat1,n,relFreq)
t2 <- panelData %>%
  filter(wave==14) %>%
  summarise(n=length(unique(id_g))) %>%
  mutate(anchorTreat1='',relFreq=1)
t <- rbind(t1,t2)
names(t) <- c("Wave 1","Frequency",'Relative frequency')
print(xtable(t,type='latex',align="rlll"),file='tableA2a.tex',
      include.rownames=F,digits=c(0,0,2,2,2))

t1 <- panelData %>%
  filter(wave==20&!is.na(anchorTreat2)) %>%
  group_by(wave,anchorTreat2) %>%
  summarise(n=n()) %>%
  mutate(N=max(cumsum(n)),relFreq=n/N) %>%
  ungroup() %>%
  select(anchorTreat2,n,relFreq)
t2 <- panelData %>%
  filter(wave==20&!is.na(anchorTreat2)) %>%
  summarise(n=length(unique(id_g))) %>%
  mutate(anchorTreat2='',relFreq=1) %>%
  ungroup() %>%
  select(anchorTreat2,n,relFreq)
t <- rbind(t1,t2)
names(t) <- c("Wave 2","Frequency",'Relative frequency')
print(xtable(t,type='latex',align="rlll"),file='tableA2b.tex',
      include.rownames=F,digits=c(0,0,2,2,2))

#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
# Table A.3: ----
# Number of observations and relative frequency of the sequence of treatments 
# over subjects in all three waves.
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
t1 <- panelData %>% 
  filter(wave==14|wave==20|wave==23) %>%
  mutate(
    anchorTreat2=factor(recode(anchorTreat2,
      'Clear, long'="Clear",'Clear, short'="Clear",
      'Vague, long'="Vague",'Vague, short'="Vague")),
    anchorTreat=paste(anchorTreat1,anchorTreat2,sep=', '),
    repeatedTreat=factor(
      ifelse(anchorTreat=='Clear, Clear','Clear twice',
      ifelse(anchorTreat=='Clear, Vague','First clear then vague',       
      ifelse(anchorTreat=='Vague, Clear','First vague then clear',
      ifelse(anchorTreat=='Vague, Vague','Vague twice',
      ifelse(anchorTreat=='Clear, NA','Clear only first',
      ifelse(anchorTreat=='NA, Clear','Clear only second',
      ifelse(anchorTreat=='Vague, NA','Vague only first',
      ifelse(anchorTreat=='NA, Vague','Vague only second',NA)))))))),
      levels=c('Clear twice','Vague twice','First clear then vague',
        'First vague then clear','Clear only first',
        'Clear only second','Vague only first','Vague only second'))) %>% 
  filter(!is.na(repeatedTreat)) %>% 
  group_by(repeatedTreat) %>% 
  summarise(n=length(unique(id_g))) %>%
  mutate(N=max(cumsum(n)),relFreq=n/N) %>%
  select(repeatedTreat,n,relFreq)
t2 <- panelData %>% 
  filter(wave==14|wave==20|wave==23) %>%
  summarise(n=length(unique(id_g))) %>%
  mutate(repeatedTreat='',relFreq=1) %>%
  ungroup() %>%
  select(repeatedTreat,n,relFreq)
t <- rbind(t1,t2)
names(t) <- c("","Frequency",'Relative frequency')
print(xtable(t,type='latex',align="rlll"),file='tableA3.tex',
  include.rownames=F,digits=c(0,0,2,2,2))

#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
# A.4 Sample characteristics and treatment balance ----
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
# Table A.4: ----
# Means and standard deviation (in parentheses) of pre-treatment variables by 
# treatment condition in the first wave each participant appears.
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
var.list <- c('younger35','older64','female','hauptSchule','abitur','married',
  'workingFulltime','unemployed','retired','leftRight','euIntegration',
  'newsCon','newsConBusiness','evaluateECB')
o <- panelData %>% 
  select(id_g,wave,anchorTreat1,anchorTreat2,age,female,education,maritalStatus,
    occupation,leftRight,evaluateECB,euIntegration,newsCon,newsConBusiness) %>%
  group_by(id_g) %>%
  mutate(firstWave=min(wave)) %>%
  ungroup() %>%
  filter(wave==firstWave) %>%
  mutate(
    younger35=ifelse(age=='16-19'|age=='20-24'|age=='25-29'|age=='30-34',1,0),
    older64=ifelse(age=='65-69'|age=='70-74'|age=='75-79',1,0),
    female=ifelse(female=='Female',1,0),
    hauptSchule=ifelse(education=='Hauptschulabschluss',1,0),
    abitur=ifelse(education=='Abitur',1,0),
    married=ifelse(maritalStatus==
      'Verheiratet und leben mit Ihrem/Ihrer Ehepartner/-in zusammen',1,0),
    workingFulltime=ifelse(occupation=='Vollzeiterwerbstätig',1,0),
    unemployed=ifelse(occupation=='Arbeitslos',1,0),
    retired=ifelse(occupation=='Im Ruhestand',1,0)) %>%
  select(var.list,anchorTreat1,anchorTreat2) %>%
  pivot_longer(cols=var.list,names_to='variable')

t <- o %>% 
  pivot_longer(cols=c(anchorTreat1,anchorTreat2),values_to='treatValue') %>%
  select(-name) %>%
  group_by(variable,treatValue) %>% 
  summarise_all(list(mean=~mean(.,na.rm=T),sd=~sd(.,na.rm=T))) %>%
  mutate(mean_sd=paste0(round(mean,2),' (',round(sd,2),')')) %>%
  select(variable,treatValue,mean_sd) %>%
  filter(!is.na(treatValue)) %>%
  pivot_wider(id_cols=variable,names_from=treatValue,values_from=mean_sd) %>%
  mutate(variable=factor(recode(variable,
    'younger35'='Share younger than 35',
    'older64'='Share older than 64',
    'female'='Share female',
    'hauptSchule'='Share Hauptschule',
    'abitur'='Share Abitur',
    'married'='Share married',
    'workingFulltime'='Share working full time',
    'unemployed'='Share unemployed',
    'retired'='Share retired',
    'leftRight'='Left-right self-placement',
    'euIntegration'='Support for EU integration',
    'newsCon'='News consumption',
    'newsConBusiness'='Business news consumption',
    'evaluateECB'='ECB approval'), 
  levels=c('Business news consumption','News consumption',
    'Left-right self-placement','Support for EU integration',
    'ECB approval','Share working full time','Share unemployed',
    'Share retired','Share married','Share Abitur','Share Hauptschule',
    'Share female','Share older than 64','Share younger than 35')))

names(t) <- c("Variable","Clear",'Vague',"Clear, short",'Clear, long',
  "Vague, short",'Vague, long') 
print(xtable(t,type='latex',align="rrllllll"),file='tableA4.tex',
      include.rownames=F,digits=c(0,0,2,2,2),floating=F)

#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
# Table A.5: ----
# Difference-in-means tests of pre-treatment variables for Clear information vs 
# vague information treatment, Clear, short information vs Clear, long 
# information, Vague, short information, and Vague, long information treatment 
# in the first wave each participant appears. We show the difference and the 
# p-values (in parentheses)
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
o.ttest <- rbind(
  o %>% group_by(variable) %>% do(tidy(t.test(value~anchorTreat1,data=.))) %>% 
    mutate(comparison='1st information treatment'),
  o %>% filter(anchorTreat2=='Clear, short'|anchorTreat2=='Clear, long') %>% 
    group_by(variable) %>% do(tidy(t.test(value~anchorTreat2,data=.))) %>% 
    mutate(comparison='2nd information treatment: clear, short vs clear, long'),
  o %>% filter(anchorTreat2=='Clear, short'|anchorTreat2=='Vague, short') %>% 
    group_by(variable) %>% do(tidy(t.test(value~anchorTreat2,data=.))) %>% 
    mutate(comparison='2nd information treatment: clear, short vs vague, short'),
  o %>% filter(anchorTreat2=='Clear, short'|anchorTreat2=='Vague, long') %>% 
    group_by(variable) %>% do(tidy(t.test(value~anchorTreat2,data=.))) %>% 
    mutate(comparison='2nd information treatment: clear, short vs vague, long'))

t <- o.ttest %>% 
  select(variable,comparison,estimate,p.value) %>%
  mutate(estimate=(-1)*estimate,
    estimate_p=paste0(round(estimate,3),' (',round(p.value,2),')')) %>%
  select(variable,comparison,estimate_p) %>%
  pivot_wider(id_cols=variable,names_from=comparison,values_from=estimate_p) %>%
  mutate(variable=factor(recode(variable,
    'younger35'='Share younger than 35',
    'older64'='Share older than 64',
    'female'='Share female',
    'hauptSchule'='Share Hauptschule',
    'abitur'='Share Abitur',
    'married'='Share married',
    'workingFulltime'='Share working full time',
    'unemployed'='Share unemployed',
    'retired'='Share retired',
    'leftRight'='Left-right self-placement',
    'euIntegration'='Support for EU integration',
    'newsCon'='News consumption',
    'newsConBusiness'='Business news consumption',
    'evaluateECB'='ECB approval'), 
    levels=c('Business news consumption','News consumption',
      'Left-right self-placement','Support for EU integration',
      'ECB approval','Share working full time','Share unemployed',
      'Share retired','Share married','Share Abitur','Share Hauptschule',
      'Share female','Share older than 64','Share younger than 35')))

names(t) <- c("Variable","Clear vs Vague","Clear, short vs Clear, long",
  "Clear, short vs Vague, short","Clear, short vs Vague, long") 
print(xtable(t,type='latex',align="rrllll"),file='tableA5.tex',
  include.rownames=F,digits=c(0,0,2,2,2),floating=F)

#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
# B Statistical appendix ----
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
# B.1 Information effects ----
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
# Figure B.1: ----
# Share of Respondent with Pairs of Reported Prior and Posterior Inflation 
# Expectations by First Information Treatment and Waves
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
pdf("figureb1.pdf",width=4,height=6)
o1 %>% 
  select(id_g,cat,anchorTreat1,value) %>%
  mutate(dev=value-1) %>%
  group_by(id_g) %>%
  mutate(
    devPrior=ifelse(cat=='Prior, Wave 1',dev,NA),
    devPrior=mean(devPrior,na.rm=T)) %>% 
  filter(cat!='Prior, Wave 1') %>%
  group_by(anchorTreat1,cat,devPrior,dev) %>%
  summarise(n=n()) %>% 
  group_by(anchorTreat1,cat) %>%
  mutate(N=max(cumsum(n)),freq=n/N) %>%
  ggplot(aes(y=dev,x=devPrior,fill=freq)) +
  facet_grid(cat~anchorTreat1) +
  geom_tile() +
  scale_y_continuous(breaks=seq(-2,9,1),labels=seq(-2,9,1)) +
  scale_x_continuous(breaks=seq(-2,9,1),labels=seq(-2,9,1)) +
  scale_fill_gradient(low="lightgray",high="gray15",limits=c(0,.15),
    breaks=c(0,.025,0.05,0.75,0.1,0.125,0.15)) + 
  labs(y='Deviation of Posterior Inflation Expectation from 1%',
     x='Deviation of Prior Inflation Expectation from 1%') + 
  guides(fill=guide_legend(title='Share of respondents')) +
  theme_bw() +
  theme(legend.position='bottom')
dev.off()

#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
# Figure B.2: ----
# Distribution of respondents' reported prior and posterior inflation 
# expectations by second information treatment and waves
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
o <- panelData %>% 
  pivot_longer(cols=c(prior,posterior)) %>%
  mutate(cat=factor(
    ifelse(wave==14&name=='prior','Prior, Wave 1',
    ifelse(wave==14&name=='posterior','Posterior, Wave 1',
    ifelse(wave==20&name=='posterior','Posterior, Wave 2',
    ifelse(wave==23&name=='posterior','Posterior, Wave 3',NA)))),
    levels=c('Prior, Wave 1','Posterior, Wave 1','Posterior, Wave 2',
      'Posterior, Wave 3')),
    anchorTreat2=factor(recode(anchorTreat2,
      'Clear, long'="Clear information",'Clear, short'="Clear information",
      'Vague, long'="Vague information",'Vague, short'="Vague information")),
    value=round(value)) %>%
  filter(!is.na(cat)&!is.na(value)&!is.na(anchorTreat2)) %>%
  group_by(anchorTreat2,cat,value) %>%
  summarise(n=n()) %>%
  mutate(N=max(cumsum(n)),freq=n/N)

pdf("figureb2.pdf",width=5,height=3)
o %>%
  ggplot(aes(y=freq,x=value,fill=anchorTreat2)) +
  geom_col(position=position_dodge(width=1)) +
  facet_wrap(~cat,ncol=2) + 
  scale_fill_manual(values=c('black','gray')) +
  scale_y_continuous(limits=c(0,.4),breaks=seq(0,.4,.1),labels=seq(-0,.4,.1)) +
  scale_x_continuous(breaks=seq(-1,10,1),labels=seq(-1,10,1)) +
  labs(y='Share of respondents',x='Inflation expectation') + 
  theme_bw(base_size = 11) +
  theme(legend.position='none',axis.text.x=element_blank(),
    axis.ticks.x=element_blank())
dev.off()

#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
# Figure B.3: ----
# Marginal effect of respondents’ reported prior inflation expectations (wave 1) 
# on reported posterior inflation expectations (wave 2 and 3) by whether first 
# and second information treatment is repeated or mixed. Participants who are 
# treated only once (because they dropped out of the panel or were recruited in 
# wave 2 only) are omitted from the analysis.
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
o0 <- panelData %>% 
  filter(wave==14|wave==20|wave==23) %>%
  mutate(
    anchorTreat2=factor(recode(anchorTreat2,
      'Clear, long'="Clear",'Clear, short'="Clear",
      'Vague, long'="Vague",'Vague, short'="Vague")),
    anchorTreat=paste(anchorTreat1,anchorTreat2,sep=', '),
    repeatedTreat=factor(
      ifelse(anchorTreat=='Clear, Clear','Clear twice',
      ifelse(anchorTreat=='Clear, Vague','First clear then vague',       
      ifelse(anchorTreat=='Vague, Clear','First vague then clear',
      ifelse(anchorTreat=='Vague, Vague','Vague twice',
      ifelse(anchorTreat=='Clear, NA','Clear only first',
      ifelse(anchorTreat=='NA, Clear','Clear only second',
      ifelse(anchorTreat=='Vague, NA','Vague only first',
      ifelse(anchorTreat=='NA, Vague','Vague only second',NA)))))))),
      levels=c('Clear twice','Vague twice','First clear then vague',
        'First vague then clear','Clear only first',
        'Clear only second','Vague only first','Vague only second'))) %>%
  filter(!is.na(repeatedTreat)) %>%
  mutate(repeatedTreatType=
      ifelse(repeatedTreat=='Clear twice'|repeatedTreat=='Vague twice','Repeated',
      ifelse(repeatedTreat=='First clear then vague'|
        repeatedTreat=='First vague then clear','Mixed','Once')),
    posterior2=ifelse(wave==20,posterior,NA),
    posterior3=ifelse(wave==23,posterior,NA),
    prior=ifelse(wave==14,prior,NA)) 

o1 <- o0 %>%
  select(id_g,repeatedTreat,repeatedTreatType,prior,posterior2,posterior3,wave,
    newsConBusiness,newsCon,evaluateECB) %>%
  group_by(id_g) %>%
  mutate(posterior2=mean(posterior2,na.rm=T),
    posterior3=mean(posterior3,na.rm=T),
    prior=mean(prior,na.rm=T)) %>% 
  ungroup() %>%
  distinct()

o2 <- o1 %>% filter(repeatedTreat=='Clear twice'|repeatedTreat=='Vague twice'|
  repeatedTreat=='First clear then vague'|repeatedTreat=='First vague then clear')

r <- rbind(
  lm_robust(posterior2~prior+newsConBusiness+newsCon+evaluateECB, 
      data=o2 %>% filter(wave==20&repeatedTreat=='Clear twice')) %>% 
    margins() %>% summary() %>% filter(factor=="prior") %>% 
    select(AME,lower,upper) %>% 
    mutate(repeatedTreat='Clear twice',wave='Wave 2'),
  lm_robust(posterior2~prior+newsConBusiness+newsCon+evaluateECB, 
      data=o2 %>% filter(wave==20&repeatedTreat=='Vague twice')) %>% 
    margins() %>% summary() %>% filter(factor=="prior") %>% 
    select(AME,lower,upper) %>% 
    mutate(repeatedTreat='Vague twice',wave='Wave 2'),
  lm_robust(posterior2~prior+newsConBusiness+newsCon+evaluateECB, 
      data=o2 %>% filter(wave==20&repeatedTreat=='First clear then vague')) %>% 
    margins() %>% summary() %>% filter(factor=="prior") %>% 
    select(AME,lower,upper) %>% 
    mutate(repeatedTreat='First clear then vague',wave='Wave 2'),
  lm_robust(posterior2~prior+newsConBusiness+newsCon+evaluateECB, 
      data=o2 %>% filter(wave==20&repeatedTreat=='First vague then clear')) %>% 
    margins() %>% summary() %>% filter(factor=="prior") %>% 
    select(AME,lower,upper) %>% 
    mutate(repeatedTreat='First vague then clear',wave='Wave 2'),
  lm_robust(posterior2~prior+newsConBusiness+newsCon+evaluateECB, 
      data=o2 %>% filter(wave==23&repeatedTreat=='Clear twice')) %>% 
    margins() %>% summary() %>% filter(factor=="prior") %>% 
    select(AME,lower,upper) %>% 
    mutate(repeatedTreat='Clear twice',wave='Wave 3'),
  lm_robust(posterior2~prior+newsConBusiness+newsCon+evaluateECB, 
      data=o2 %>% filter(wave==23&repeatedTreat=='Vague twice')) %>% 
    margins() %>% summary() %>% filter(factor=="prior") %>% 
    select(AME,lower,upper) %>% 
    mutate(repeatedTreat='Vague twice',wave='Wave 3'),
  lm_robust(posterior2~prior+newsConBusiness+newsCon+evaluateECB, 
      data=o2 %>% filter(wave==23&repeatedTreat=='First clear then vague')) %>% 
    margins() %>% summary() %>% filter(factor=="prior") %>% 
    select(AME,lower,upper) %>% 
    mutate(repeatedTreat='First clear then vague',wave='Wave 3'),
  lm_robust(posterior2~prior+newsConBusiness+newsCon+evaluateECB, 
      data=o2 %>% filter(wave==23&repeatedTreat=='First vague then clear')) %>% 
    margins() %>% summary() %>% filter(factor=="prior") %>% 
    select(AME,lower,upper) %>% 
    mutate(repeatedTreat='First vague then clear',wave='Wave 3'))

pdf("figureb3.pdf",,height=3)
r %>%
  ggplot() +
  geom_line(aes(y=AME,x=repeatedTreat,group=wave,linetype=wave,color=wave),
            position=position_dodge2(width=.3)) + 
  geom_pointrange(aes(y=AME,x=repeatedTreat,ymin=lower,ymax=upper,color=wave,fill=wave),
                  shape=21,position=position_dodge2(width=.3)) + 
  scale_color_manual(values=c('black','black')) +
  scale_fill_manual(values=c('black','white')) +
  labs(y='Marginal effect of prior',x='') + 
  theme_bw(base_size = 11) +
  theme(legend.position='bottom',legend.title=element_blank(),
        strip.background=element_blank(),strip.text=element_blank(),
        axis.text.x=element_text(angle=45,hjust=1,vjust=1))
dev.off()

#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
# Table B.1: ----
# Linear Regression of Respondents' Reported Posterior Inflation Expectations an 
# Indicator of the Clear Information Treatment, an Indicator of whether the 
# Inflation Expectation is a Prior or Posterior, and the Interaction of the Two 
# Variables.  
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
o <- panelData %>% filter(wave==14) %>% 
  select(prior,posterior,anchorTreat1,id_g) %>%
  pivot_longer(cols=c(prior,posterior)) %>%
  mutate(name=factor(name,levels=c('prior','posterior')))

m <- o %>% 
  mutate(anchorTreat1=factor(anchorTreat1)) %>%
  lm_robust(value~name*relevel(anchorTreat1,ref='Vague'),
            clusters=id_g,data=.) 

texreg(m,
  digits=3,single.row=F,include.ci=F,stars=c(.1,.05,.01),
  reorder.coef=c(2,3,4,1),
  custom.model.name=c('Wave 1'),
  custom.coef.names=c('Constant','Clear information','Indicator for posterior',
    'Clear information x Indicator for posterior'),
  table=F,
  file="tableb1.tex") 

#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
# Table B.2: ---
# Linear Regression of Posterior Inflation Expectation in Waves 2 and 3 on an 
# Indicator of the Second Information Treatment, Prior Inflation Expectation, 
# Covariates, and Their Interactions.  
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
o <- panelData %>% 
  group_by(id_g) %>%
  mutate(prior=ifelse(wave==14,prior,NA),
    prior=mean(prior,na.rm=T),
    anchorTreat1=factor(anchorTreat1,levels=c('Vague','Clear'))) %>%
  ungroup()

m1 <- o %>% filter(wave==14) %>%
  lm_robust(posterior~anchorTreat1, data=.)
m2 <- o %>% filter(wave==20) %>%
  lm_robust(posterior~anchorTreat1, data=.)
m3 <- o %>% filter(wave==23) %>%
  lm_robust(posterior~anchorTreat1, data=.)
m4 <- o %>% filter(wave==14) %>%
  lm_robust(posterior~anchorTreat1*prior, data=.)
m5 <- o %>% filter(wave==20) %>%
  lm_robust(posterior~anchorTreat1*prior, data=.)
m6 <- o %>% filter(wave==23) %>%
  lm_robust(posterior~anchorTreat1*prior, data=.)
m7 <- o %>% filter(wave==14) %>%
  lm_robust(posterior~anchorTreat1*(prior+newsConBusiness+newsCon+evaluateECB), data=.)
m8 <- o %>% filter(wave==20) %>%
  lm_robust(posterior~anchorTreat1*(prior+newsConBusiness+newsCon+evaluateECB), data=.)
m9 <- o %>% filter(wave==23) %>%
  lm_robust(posterior~anchorTreat1*(prior+newsConBusiness+newsCon+evaluateECB), data=.)

texreg(list(m1,m2,m3,m4,m5,m6,m7,m8,m9),
  digits=3,single.row=F,include.ci=F,stars=c(.1,.05,.01),
  reorder.coef=c(2,3,4,5,6,7,8,9,10,1),
  custom.model.name=c('Wave 1','Wave 2','Wave 3','Wave 1','Wave 2','Wave 3',
    'Wave 1','Wave 2','Wave 3'),
  custom.coef.names=c('Constant','Clear information','Prior',
    'Clear information x prior','Business news consumption','News consumption',
    'Positive evaluation of ECB','Clear information x Business news consumption',
    'Clear information x News consumption',
    'Clear information x Positive evaluation of ECB'),
  table=F,
  file="tableb2.tex") 

#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
# Figure B.4: ----
# Distribution of respondents’ reported wave 1 posterior inflation expectations 
# by first information treatment
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
o <- panelData %>% 
  filter(wave==14) %>%
  pivot_longer(cols=posterior) %>%
  mutate(cat=factor(
      ifelse(wave==14&name=='posterior','Posterior, Wave 1',
      ifelse(wave==20&name=='posterior','Posterior, Wave 2',
      ifelse(wave==23&name=='posterior','Posterior, Wave 3',NA))),
      levels=c('Posterior, Wave 1','Posterior, Wave 2','Posterior, Wave 3')),
    anchorTreat1=factor(recode(anchorTreat1,
      'Clear'='Clear information','Vague'='Vague information')),
    value=round(value),
    prior=ifelse(prior>8,8,prior)) %>%
  group_by(id_g) %>%
  mutate(
    prior=ifelse(wave==14,prior,NA),
    prior=mean(prior,na.rm=T)) %>%
  filter(!is.na(cat)&!is.na(value)&!is.na(anchorTreat1)) 

pdf("figureb4.pdf",width=5,height=6)
o %>%
  group_by(prior,anchorTreat1,cat,value) %>%
  summarise(n=n()) %>%
  mutate(N=max(cumsum(n)),freq=n/N) %>%
  ggplot(aes(y=freq,x=value,fill=anchorTreat1)) +
  geom_col(position=position_dodge(width=.7)) +
  facet_grid(prior~.) + 
  scale_fill_manual(values=c('black','gray')) +
  scale_x_continuous(breaks=seq(-1,10,1),labels=seq(-1,10,1)) +
  labs(y='Share of respondents',x='Wave 1 Posterior Inflation expectation') + 
  theme_bw() +
  theme(legend.position='none')
dev.off()

#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
# B.2 Information effects by ECB approval ---- 
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
# Figure B.5 ----
# Distribution of respondents’ approval with the performance of the ECB by first
# information treatment
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
pdf("figureb5.pdf",height=3)
panelData %>% 
  filter(wave==14) %>% 
  group_by(anchorTreat1,evaluateECB) %>%
  summarise(n=n()) %>%
  mutate(N=max(cumsum(n)),relFreq=n/N) %>%
  ggplot(aes(y=relFreq,x=evaluateECB,fill=anchorTreat1,color=anchorTreat1)) +
  geom_col(position=position_dodge(width=.5)) +
  scale_color_manual(values=c('black','darkgray')) +
  scale_fill_manual(values=c('black','darkgray')) +
  labs(y='Share of respondents',x='pproval of ECB performance') + 
  theme_bw(base_size=11) +
  theme(legend.position='bottom',legend.title=element_blank())
dev.off()

#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
# Information effects by occupation status ----
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
# Figure B.6: ----
# Marginal Effect of Priors on Posterior Inflation Expectation by Change in 
# Occupation Status, First Wave Information Treatment, and Waves.
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
o <- panelData %>% 
  group_by(id_g) %>%
  mutate(prior=ifelse(wave==14,prior,NA),
    posterior2=ifelse(wave==20,posterior,NA),
    posterior3=ifelse(wave==23,posterior,NA),
    prior=mean(prior,na.rm=T),
    anchorTreat1=factor(anchorTreat1,levels=c('Vague','Clear')),
    howManyOcc=n_distinct(occupation),
    occChange=factor(ifelse(howManyOcc>=3,'Changed\noccupation\nstatus','Control'),
    levels=c('Control','Changed\noccupation\nstatus'))) %>%
  ungroup()

r <- rbind(
  o %>%
    group_by(occChange) %>%
    do(lm_robust(prior~1,data=.) %>% tidy()) %>%
    mutate(repeatedTreat=str_remove(term,'repeatedTreat'),variable="Prior"),
  o %>%
    group_by(occChange) %>%
    do(lm_robust(posterior2~1,data=.) %>% tidy()) %>%
    mutate(repeatedTreat=str_remove(term,'repeatedTreat'),variable="Posterior, Wave 2"),
  o %>%
    group_by(occChange) %>%
    do(lm_robust(posterior3~1,data=.) %>% tidy()) %>%
    mutate(repeatedTreat=str_remove(term,'repeatedTreat'),variable="Posterior, Wave 3")) %>%
  mutate(
    variable=factor(variable,levels=c('Prior','Posterior, Wave 2','Posterior, Wave 3')))

pdf("figureb6.pdf",height=2)
r %>% 
  ggplot(aes(y=estimate,x=occChange,ymin=conf.low,ymax=conf.high,color=variable,
    fill=variable)) +
  geom_pointrange(position=position_dodge(width=.5),shape=21) +
  coord_flip() +
  scale_color_manual(values=c('black','black','gray')) +
  scale_fill_manual(values=c('black','white','gray')) +
  labs(y='Inflation expectation',x='') + 
  theme_bw() +
  theme(legend.position='bottom',legend.title=element_blank())
dev.off()

#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
# B.4 Information effects by region and gender ---- 
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
o <- panelData %>% 
  pivot_longer(cols=c(prior,posterior)) %>%
  mutate(cat=factor(
    ifelse(wave==14&name=='prior','Prior, Wave 1',
    ifelse(wave==14&name=='posterior','Posterior, Wave 1',
    ifelse(wave==20&name=='posterior','Posterior, Wave 2',
    ifelse(wave==23&name=='posterior','Posterior, Wave 3',NA)))),
    levels=c('Prior, Wave 1','Posterior, Wave 1','Posterior, Wave 2',
      'Posterior, Wave 3')), 
    value=round(value)) %>%
  filter(!is.na(cat)&!is.na(value)) 

o %>% 
  filter(!is.na(east)) %>%
  group_by(wave,cat) %>%
  do(lm_robust(value~east,clusters=id_g,data=.) %>% tidy()) %>%
  filter(term=='east')

o %>% 
  filter(!is.na(female)) %>%
  mutate(female=factor(female)) %>%
  group_by(wave,cat) %>%
  do(lm_robust(value~relevel(female,ref='Male'),clusters=id_g,data=.) %>% 
    tidy()) %>%
  filter(term!='(Intercept)')

#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
# Figure B.7: ----
# Distribution of respondents' reported prior and posterior inflation 
# expectations by first information treatment, waves, and whether they 
# currently reside in East or West Germany.
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
o <- panelData %>% 
  pivot_longer(cols=c(prior,posterior)) %>%
  mutate(cat=factor(
    ifelse(wave==14&name=='prior','Prior, Wave 1',
    ifelse(wave==14&name=='posterior','Posterior, Wave 1',
    ifelse(wave==20&name=='posterior','Posterior, Wave 2',
    ifelse(wave==23&name=='posterior','Posterior, Wave 3',NA)))),
    levels=c('Prior, Wave 1','Posterior, Wave 1','Posterior, Wave 2',
      'Posterior, Wave 3')),
    anchorTreat1=factor(recode(anchorTreat1,
      'Clear'='Clear information','Vague'='Vague information')),
    value=round(value)) %>%
  filter(!is.na(cat)&!is.na(value)&!is.na(anchorTreat1)) 

pdf("figureb7.pdf",width=6,height=4)
rbind(
  o %>%
    group_by(anchorTreat1,cat,value) %>%
    summarise(n=n()) %>%
    mutate(N=max(cumsum(n)),freq=n/N,east=2),
  o %>%
    filter(!is.na(east)) %>%
    group_by(east,anchorTreat1,cat,value) %>%
    summarise(n=n()) %>%
    mutate(N=max(cumsum(n)),freq=n/N)) %>%
  mutate(east=factor(recode(east,`0`='East',`1`='West',`2`='Germany'),
                     levels=c('Germany','West','East'))) %>%
  ggplot(aes(y=freq,x=value,fill=anchorTreat1)) +
  geom_col(position=position_dodge(width=1)) +
  facet_grid(east~cat) + 
  scale_fill_manual(values=c('black','gray')) +
  scale_y_continuous(limits=c(0,.5),breaks=seq(0,.5,.1),labels=seq(-0,.5,.1)) +
  scale_x_continuous(breaks=seq(-1,10,1),labels=seq(-1,10,1)) +
  labs(y='Share of respondents',x='Inflation expectation') + 
  theme_bw() +
  theme(legend.position='none')
dev.off()

#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
# Figure B.8: ----
# Marginal effect of priors on posterior inflation expectation by first 
# information treatment, waves, and whether they currently reside in East or 
# West Germany.
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
o <- panelData %>% 
  group_by(id_g) %>%
  mutate(prior=ifelse(wave==14,prior,NA),
    prior=mean(prior,na.rm=T),
    anchorTreat1=factor(anchorTreat1,levels=c('Vague','Clear')),
    east=factor(recode(east,`0`='East',`1`='West'))) %>%
  filter(!is.na(east)) %>%
  ungroup()

r <- rbind(
  lm_robust(posterior~prior*(evaluateECB+east+newsCon), 
      data=o %>% filter(wave==14&anchorTreat1=="Clear")) %>% 
    margins(variables='prior',at=list(east=c('East','West'))) %>% 
    summary() %>% filter(factor=="prior") %>% select(AME,lower,upper,east) %>%
    mutate(t='Clear information',wave='Wave 1'),
  lm_robust(posterior~prior*(evaluateECB+east+newsCon), 
      data=o %>% filter(wave==14&anchorTreat1=="Vague")) %>% 
    margins(variables='prior',at=list(east=c('East','West'))) %>% 
    summary() %>% filter(factor=="prior") %>% select(AME,lower,upper,east) %>%
    mutate(t='Vague information',wave='Wave 1'),
  lm_robust(posterior~prior*(evaluateECB+east+newsCon), 
      data=o %>% filter(wave==20&anchorTreat1=="Clear")) %>% 
    margins(variables='prior',at=list(east=c('East','West'))) %>% 
    summary() %>% filter(factor=="prior") %>% select(AME,lower,upper,east) %>%
    mutate(t='Clear information',wave='Wave 2'),
  lm_robust(posterior~prior*(evaluateECB+ +newsCon), 
      data=o %>% filter(wave==20&anchorTreat1=="Vague")) %>% 
    margins(variables='prior',at=list(east=c('East','West'))) %>% 
    summary() %>% filter(factor=="prior") %>% select(AME,lower,upper,east) %>%
    mutate(t='Vague information',wave='Wave 2'),
  lm_robust(posterior~prior*(evaluateECB+east+newsCon),  
      data=o %>% filter(wave==23&anchorTreat1=="Clear")) %>% 
    margins(variables='prior',at=list(east=c('East','West'))) %>% 
    summary() %>% filter(factor=="prior") %>% select(AME,lower,upper,east) %>%
    mutate(t='Clear information',wave='Wave 3'),
  lm_robust(posterior~prior*(evaluateECB+east+newsCon), 
      data=o %>% filter(wave==23&anchorTreat1=="Vague")) %>% 
    margins(variables='prior',at=list(east=c('East','West'))) %>%  
    summary() %>% filter(factor=="prior") %>% select(AME,lower,upper,east) %>%
    mutate(t='Vague information',wave='Wave 3'))

pdf("figureb8.pdf",height=2.5)
r %>%
  ggplot() +
  geom_line(aes(y=AME,x=east,group=wave,linetype=wave,color=wave),
    position=position_dodge2(width=.5)) + 
  geom_pointrange(aes(y=AME,x=east,ymin=lower,ymax=upper,color=wave,
    fill=wave),shape=21,position=position_dodge2(width=.5)) + 
  facet_grid(~t) +
  scale_color_manual(values=c('black','black','darkgray')) +
  scale_fill_manual(values=c('black','white','darkgray')) +
  labs(y='Marginal effect of prior',x='') + 
  theme_bw(base_size = 11) +
  theme(legend.position='bottom',legend.title=element_blank())
dev.off()

#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
# Figure B.9: ----
# Distribution of respondents' reported prior and posterior inflation 
# expectations by first information treatment, waves, and gender.
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
o <- panelData %>% 
  pivot_longer(cols=c(prior,posterior)) %>%
  mutate(cat=factor(
    ifelse(wave==14&name=='prior','Prior, Wave 1',
    ifelse(wave==14&name=='posterior','Posterior, Wave 1',
    ifelse(wave==20&name=='posterior','Posterior, Wave 2',
    ifelse(wave==23&name=='posterior','Posterior, Wave 3',NA)))),
    levels=c('Prior, Wave 1','Posterior, Wave 1','Posterior, Wave 2',
      'Posterior, Wave 3')),
    anchorTreat1=factor(recode(anchorTreat1,
      'Clear'='Clear information','Vague'='Vague information')),
    value=round(value)) %>%
  filter(!is.na(cat)&!is.na(value)&!is.na(anchorTreat1)) 

pdf("figureb9.pdf",width=6,height=4)
rbind(
  o %>%
    group_by(anchorTreat1,cat,value) %>%
    summarise(n=n()) %>%
    mutate(N=max(cumsum(n)),freq=n/N,female='All'),
  o %>%
    filter(!is.na(female)) %>%
    group_by(female,anchorTreat1,cat,value) %>%
    summarise(n=n()) %>%
    mutate(N=max(cumsum(n)),freq=n/N)) %>%
  mutate(female=factor(female,levels=c('All','Female','Male'))) %>%
  ggplot(aes(y=freq,x=value,fill=anchorTreat1)) +
  geom_col(position=position_dodge(width=1)) +
  facet_grid(female~cat) + 
  scale_fill_manual(values=c('black','gray')) +
  scale_y_continuous(limits=c(0,.5),breaks=seq(0,.5,.1),labels=seq(-0,.5,.1)) +
  scale_x_continuous(breaks=seq(-1,10,1),labels=seq(-1,10,1)) +
  labs(y='Share of respondents',x='Inflation expectation') + 
  theme_bw() +
  theme(legend.position='none')
dev.off()

#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
# Figure B.10: ----
# Marginal effect of priors on posterior inflation expectation by first 
# information treatment, waves, and gender.
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
o <- panelData %>% 
  group_by(id_g) %>%
  mutate(prior=ifelse(wave==14,prior,NA),
    prior=mean(prior,na.rm=T),
    anchorTreat1=factor(anchorTreat1,levels=c('Vague','Clear'))) %>%
  filter(!is.na(female)) %>%
  ungroup()

r <- rbind(
  lm_robust(posterior~prior*(evaluateECB+female+newsCon), 
      data=o %>% filter(wave==14&anchorTreat1=="Clear")) %>% 
    margins(variables='prior',at=list(female=c('Female','Male'))) %>% 
    summary() %>% filter(factor=="prior") %>% select(AME,lower,upper,female) %>%
    mutate(t='Clear information',wave='Wave 1'),
  lm_robust(posterior~prior*(evaluateECB+female+newsCon), 
      data=o %>% filter(wave==14&anchorTreat1=="Vague")) %>% 
    margins(variables='prior',at=list(female=c('Female','Male'))) %>% 
    summary() %>% filter(factor=="prior") %>% select(AME,lower,upper,female) %>%
    mutate(t='Vague information',wave='Wave 1'),
  lm_robust(posterior~prior*(evaluateECB+female+newsCon), 
      data=o %>% filter(wave==20&anchorTreat1=="Clear")) %>% 
    margins(variables='prior',at=list(female=c('Female','Male'))) %>% 
    summary() %>% filter(factor=="prior") %>% select(AME,lower,upper,female) %>%
    mutate(t='Clear information',wave='Wave 2'),
  lm_robust(posterior~prior*(evaluateECB+ +newsCon), 
      data=o %>% filter(wave==20&anchorTreat1=="Vague")) %>% 
    margins(variables='prior',at=list(female=c('Female','Male'))) %>%  
    summary() %>% filter(factor=="prior") %>% select(AME,lower,upper,female) %>%
    mutate(t='Vague information',wave='Wave 2'),
  lm_robust(posterior~prior*(evaluateECB+female+newsCon),  
      data=o %>% filter(wave==23&anchorTreat1=="Clear")) %>% 
    margins(variables='prior',at=list(female=c('Female','Male'))) %>% 
    summary() %>% filter(factor=="prior") %>% select(AME,lower,upper,female) %>%
    mutate(t='Clear information',wave='Wave 3'),
  lm_robust(posterior~prior*(evaluateECB+female+newsCon), 
      data=o %>% filter(wave==23&anchorTreat1=="Vague")) %>% 
    margins(variables='prior',at=list(female=c('Female','Male'))) %>%  
    summary() %>% filter(factor=="prior") %>% select(AME,lower,upper,female) %>%
    mutate(t='Vague information',wave='Wave 3'))

pdf("figureb10.pdf",height=2.5)
r %>%
  ggplot() +
  geom_line(aes(y=AME,x=female,group=wave,linetype=wave,color=wave),
    position=position_dodge2(width=.5)) + 
  geom_pointrange(aes(y=AME,x=female,ymin=lower,ymax=upper,color=wave,
    fill=wave),shape=21,position=position_dodge2(width=.5)) + 
  facet_grid(~t) +
  scale_color_manual(values=c('black','black','darkgray')) +
  scale_fill_manual(values=c('black','white','darkgray')) +
  labs(y='Marginal effect of prior',x='') + 
  theme_bw(base_size = 11) +
  theme(legend.position='bottom',legend.title=element_blank())
dev.off()

#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#

          






  



